/* 2014/10/24 */
package com.cosmos.quartz.control;

import java.util.Calendar;
import java.util.Date;

public class AgentControlService {

	public static final String OPERATION_PAUSE = "Pause";
	
	public static final String OPERATION_PAUSE_ALL = "PauseAll";
	
	public static final String OPERATION_RESUME = "Resume";
	
	public static final String OPERATION_RESUME_ALL = "ResumeAll";
	
	public static final String OPERATION_REPORT = "Report";
	
	public static final String OPERATION_REPORT_ALL = "ReportAll";
	
	public static final String OPERATION_TRIGGER = "Trigger";
	
	public static final String OPERATION_TRIGGER_All = "TriggerAll";
	
	public static final String[] REPORT_OPERATIONS = new String[]{
		AgentControlService.OPERATION_REPORT, AgentControlService.OPERATION_REPORT_ALL,
		AgentControlService.OPERATION_PAUSE, AgentControlService.OPERATION_PAUSE_ALL,
		AgentControlService.OPERATION_RESUME, AgentControlService.OPERATION_RESUME_ALL};
	
	public static boolean isSingleJobOperation(String operation) {
		return OPERATION_PAUSE.equals(operation) || OPERATION_RESUME.equals(operation) || OPERATION_REPORT.equals(operation);
	}
	
	public static boolean isAllJobOperation(String operation) {
		return OPERATION_PAUSE_ALL.equals(operation) || OPERATION_RESUME_ALL.equals(operation) || OPERATION_REPORT_ALL.equals(operation);
	}
	
	/**
	 * Returns default value of time, requests after which are considered as valid.  
	 * Because agent control is not real time, request over long time is not valid.
	 */
	public static Date getValidRequestStartTime() {
		Calendar calendar = Calendar.getInstance();
		calendar.add(Calendar.HOUR_OF_DAY, -1);
		Date time = calendar.getTime();		
		
		int offset = calendar.getTimeZone().getRawOffset();		
		return new Date(time.getTime() - offset);
	}
	
	/**
	 * Returns default value of time, responses after which are considered as valid.  
	 * Because agent control is not real time, response over long time is not valid.
	 * @return
	 */
	public static Date getValidResponseStartTime() {
		Calendar calendar = Calendar.getInstance();
		calendar.add(Calendar.HOUR_OF_DAY, -1);
		Date time = calendar.getTime();		
		
		int offset = calendar.getTimeZone().getRawOffset();		
		return new Date(time.getTime() - offset);
	}
}
